const { List } = antd;

const IdeaList = ({ onSelect, data }) => {
    const [dataSource, setDataSource] = useState(data);
    const [selectedItem, setSelectedItem] = useState(null);

    useEffect(() => {
        setDataSource(data)
    }, [data]);
    const handleItemClick = (item) => {
        setSelectedItem(item);
        if (typeof onSelect === 'function') {
            onSelect(item);
        }
    };

    return (
        <List
            dataSource={dataSource}
            renderItem={(item) => (
                <List.Item
                    key={item.id}
                    onClick={() => handleItemClick(item)}
                    style={{
                        cursor: 'pointer',
                        backgroundColor: item === selectedItem ? '#f0f0f0' : 'transparent'
                    }}
                >
                    <div>
                        <h3>{item.title}</h3>
                        <p>类型: {item.genre}</p>
                    </div>
                </List.Item>
            )}
        />
    );
};

